﻿Imports System.Linq
Imports TNCDAL

Public Class CustomerController
    Private objRepository As New CustomerRepository

    Public Function SelectAllRecords() As IQueryable(Of tblCustomer)
        Return objRepository.SelectAllRecords()
    End Function

    Public Function GetCustomerByCompany(ByVal id_company As Integer) As IQueryable(Of tblCustomer)
        Return objRepository.GetCustomerByCompany(id_company)
    End Function

    Public Function SelectRecordById(ByVal id As Integer) As tblCustomer
        Return objRepository.SelectRecordById(id)
    End Function

    Public Sub Insert(ByVal obj As tblCustomer)
        objRepository.Insert(obj)
    End Sub

    Public Sub Update(ByVal obj As tblCustomer)
        objRepository.Update(obj)
    End Sub

    Public Sub Delete(ByVal id As Integer)
        objRepository.DeleteRecordById(id)
    End Sub

    Public Function SelectCustomAllCustomers() As IQueryable
        Dim query = (From p In objRepository.SelectAllRecords()
                     Select p.ID_Customer, p.CustomerName, Company = p.tblCompany.Name).OrderBy(Function(p) p.CustomerName)
        Return query
    End Function


    Public Function SelectRecordByName(ByVal isExport As Boolean, ByVal CompanyName As String, ByVal CustomerName As String) As tblCustomer
        Dim query = (From p In SelectAllRecords()
                    Where p.CustomerName = CustomerName And p.tblCompany.Name = CompanyName
                    Select p).SingleOrDefault()
        Return query
    End Function

    'Public Function SelectRecordByName(ByVal isExport As Boolean, ByVal CompanyName As String, ByVal CustomerName As String) As tblCustomer
    '    Dim value As Integer = 0
    '    If isExport Then
    '        value = 1
    '    End If
    '    Return objRepository.SelectRecordByName(value, CompanyName, CustomerName)
    'End Function
    
End Class